<?php

class Users_BrowseSuccessView extends SrsUsersBaseView
{
	public function executeHtml(AgaviRequestDataHolder $rd)
	{
		$this->setupHtml($rd);

		$users = $this->fetchUsers($rd);

		$this->setAttribute('noUsers', empty($users));
		$this->setAttribute('users', $users);
	}

	private function fetchUsers(AgaviRequestDataHolder $rd)
	{
		$page    = (int)$rd->getParameter('page', 1);
		$perPage = (int)$rd->getParameter('perPage', 10);
		
		$q = Doctrine_Query::create()
			->from('User u')
			->orderBy('u.email ASC');

		$pager = new Doctrine_Pager($q, $page, $perPage);

		$users = $pager->execute(array(), Doctrine::HYDRATE_ARRAY);

		$this->setAttribute('pager', $pager);
		$this->setAttribute('perPage', $perPage);

		return $users;
	}
}